<template>
  <div>
    <lbt :dataList="dataList"></lbt>
    <neirong :arr="arr"></neirong>
  </div>
</template>
<style scoped>
</style>
<script>
import lbt from "../component/teshu1.vue";
import wz from "../component/teshu2.vue";
import axios from "axios";
export default {
  components: {
    /* 声明使用组件 */ lbt: lbt /* 前面位名称后面为之前给组件起的名 */,
    neirong: wz,
  },
  data() {
    return {
      dataList: [],
      currentIndex: 0, //默认显示图片
      timer: null, //定时器
      arr: [],
      bool: false,
      n: "",
      arrNew: [],
      srcc: `https://jd.itying.com/`,
      arr1: [],
    };
  },
  methods: {
    cha(index) {
      this.bool = true;
      this.n = this.arr[index]._id;
      this.axios("https://jd.itying.com/api/plist?cid=" + this.n).then(
        (res) => {
          this.arrNew = res.data.result;
          console.log(this.arrNew);
        }
      );
    },
    huan(index) {},
    gotoPage(index) {
      this.currentIndex = index;
    },
    //定时器
    runInv() {
      this.timer = setInterval(() => {
        this.gotoPage(this.nextIndex);
      }, 1000);
    },
  },
  computed: {
    swiper() {
      return this.$refs.mySwiper.swiper;
    },
    prevIndex() {
      if (this.currentIndex == 0) {
        return this.dataList.length - 1;
      } else {
        return this.currentIndex - 1;
      }
    },
    //下一张
    nextIndex() {
      if (this.currentIndex == this.dataList.length - 1) {
        return 0;
      } else {
        return this.currentIndex + 1;
      }
    },
  },
  mounted() {
    // this.swiper.slideTo(3, 1000, false);
    this.axios("https://jd.itying.com/api/pcate").then((res) => {
      this.arr = res.data.result;
    });
    this.axios("https://jd.itying.com/api/focus").then((res) => {
      this.arr1 = res.data.result;
      this.arr1.forEach((item) => {
        this.dataList.push(this.srcc + item.pic);
      });
    });
  },
};
</script>
